import React from 'react'

export default class ComponentB extends React.Component {
  constructor() {
    super()
    this.state = {
      initCount: this.$store.getState().count
    }

    // 在组件中监听state数据的改变
    this.$store.subscribe(() => {
      console.log(this.$store.getState())
      this.setState({
        initCount: this.$store.getState().count
      })
    })
  }
  render() {
    return <div className="box" style={{ backgroundColor: "skyblue" }}>
      <h3>B组件</h3>
      <p>{this.state.initCount}</p>
    </div>
  }
}